home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 11 / AMUG BBS in a Box Volume XI (April 1994) (MacWizards).iso / Files / QuickTime / QT Tools / Moovtopics.c.sit / moovtopics.c
Encoding:
C/C++ Source or Header  |  1992-06-22  |  2.8 KB  |  99 lines  |  [TEXT/EDIT]

  1. #include <Movies.h>
  2. #include <string.h>
  3.  
  4. void main(void);
  5.  
  6. void main()
  7. {
  8.     OSErr err;
  9.     Movie themovie;
  10.     FSSpec tempspec;
  11.     PicHandle pichand;
  12.     SFTypeList typelist;
  13.     OSType mediatypes[1];
  14.     short saveref, resref, outref, frame;
  15.     StandardFileReply getreply, putreply;
  16.     TimeValue fromtime, thetime, duration;
  17.     
  18.     /* user gets movie file */
  19.     typelist[0] = 'MooV';
  20.     StandardGetFile(nil, 1, typelist, &getreply);
  21.     if (!getreply.sfGood)
  22.         return;
  23.         
  24.     /* copy the FSSpec from the reply record and append suffix to copy of file name */
  25.     tempspec = getreply.sfFile;
  26.     PtoCstr(tempspec.name);
  27.     strcat((char *)tempspec.name, ".PICS");
  28.     CtoPstr((char *)tempspec.name);
  29.     
  30.     /* user puts new PICS file */
  31.     StandardPutFile("\pSave PICS file as:", tempspec.name, &putreply);
  32.     if (!putreply.sfGood)
  33.         return;
  34.         
  35.     /* initialize movie toolbox */
  36.     EnterMovies();
  37.     
  38.     /* open the movie file, get the movie from it, then close it */
  39.     OpenMovieFile(&getreply.sfFile, &resref, fsRdPerm);
  40.     NewMovieFromFile(&themovie, resref, nil, nil, newMovieActive, nil);
  41.     CloseMovieFile(resref);
  42.     
  43.     /* save the current resource file for later restoration */
  44.     saveref = CurResFile();
  45.     
  46.     /* delete any existing PICS file, create resource file, and open it */
  47.     FSpDelete(&putreply.sfFile);
  48.     FSpCreateResFile(&putreply.sfFile, 'RUNT', 'PICS', 0);
  49.     outref = FSpOpenResFile(&putreply.sfFile, fsWrPerm);
  50.     UseResFile(outref);
  51.     
  52.     /* set up some variables */
  53.     fromtime = 0;
  54.     frame = 128;
  55.     mediatypes[0] = VideoMediaType;
  56.     
  57.     /* get the first frame from the movie and save it */
  58.     /* the 0 means the very beginning of the movie */
  59.     pichand = GetMoviePict(themovie, 0);
  60.     if (pichand) {
  61.         AddResource((Handle)pichand, 'PICT', frame, "\p");
  62.         WriteResource((Handle)pichand);
  63.         ReleaseResource((Handle)pichand);
  64.         frame ++;    /* increment resource id number */
  65.     }
  66.     
  67.     /* now get each successive frame from movie and save it */
  68.     /* the break will exit from the inifinite loop */
  69.     do {
  70.     
  71.         /* get the time and duration of the next video media sample in the movie */
  72.         GetMovieNextInterestingTime(themovie, nextTimeMediaSample, 1, mediatypes, 
  73.             fromtime, (Fixed)1L<<16, &thetime, &duration);
  74.             
  75.         /* if the time comes back -1, then there are no more samples; so exit loop */
  76.         if (thetime < 0)
  77.             break;
  78.             
  79.         /* otherwise, continue to get a PICT from the movie based on
  80.         /* the time returned, and save it off to the resource file */
  81.         pichand = GetMoviePict(themovie, thetime);
  82.         if (pichand) {
  83.             AddResource((Handle)pichand, 'PICT', frame, "\p");
  84.             WriteResource((Handle)pichand);
  85.             ReleaseResource((Handle)pichand);
  86.             frame ++;
  87.         }
  88.         
  89.         /* set the search start time to the end of the last sample */
  90.         fromtime = thetime + duration - 1;
  91.     } while (true);
  92.     
  93.     /* clean up and close down */
  94.     DisposeMovie(themovie);
  95.     UpdateResFile(outref);
  96.     CloseResFile(outref);
  97.     UseResFile(saveref);
  98.     ExitMovies();
  99. }